<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* CRM In Customer */
class Crm extends Controller {
	
	function Crm(){
		if(!$this->session->userdata('user_id')){
			redirect($this->config->item('auth'));
		}
        
        if(!$this->session->userdata('menu1')==1){
			redirect($this->config->item('dashboard'));
		}
        
		$this->load->model('customers');
        $this->load->model('status');
        $this->load->model('groups');
        $this->load->model('sources');
        $this->load->model('sectors');
	}
	
	function index($id=1){
	    if($this->session->userdata('user_pos')== $this->config->item('se')):
            redirect('customersdna/crm/individual/',301);
        endif;       
	    if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna'))  ):
                $corpo 		    	 = 'Corporate';
                $corpo_link 		 = $this->config->item('customerdna');
                $corpo_active   	 = $this->config->item('active');
				
				$indiv          	 = 'Individual';
                $indiv_link     	 = $this->config->item('custdna_individual');
                $indiv_active   	 = $this->config->item('empty');
					
				$add 		        = $this->lang->line('add');
    			$add_link 	        = $this->config->item('custdna_add');
    			$add_active         = $this->config->item('empty');
    			
    			$adv_search         = $this->lang->line('adv_search');
    			$adv_search_link    = $this->config->item('custdna_search');
                $adv_search_active  = $this->config->item('empty');
                
                $export             = $this->lang->line('export');
    			$export_link        = $this->config->item('custdna_excel');
                $export_active      = $this->config->item('empty');
                
                $import             = $this->lang->line('import');
    			$import_link        = $this->config->item('custdna_import');
                $import_active      = $this->config->item('empty');
                
                
                $prospect           = $this->lang->line('prospect');
    			$prospect_link      = $this->config->item('custdna_prospect');
                $prospect_active    = $this->config->item('empty');
    			
    			$rolling			= $this->lang->line('rolling');
    			$rolling_link		= $this->config->item('custdna_rolling');
    			$rolling_active     = $this->config->item('empty');
    			
                $backroll			= "";
    			$backroll_link		= "";
    			$backroll_active    = "";
           elseif(($this->session->userdata('user_group')== $this->config->item('user_dna')) ):
				if ($this->session->userdata('user_pos')== $this->config->item('ta')):
                    $corpo 		    = 'Corporate';
                    $corpo_link 	= $this->config->item('customerdna');
                    $corpo_active   = $this->config->item('active');
                    
                    $indiv          = "";
                    $indiv_link     = "";
                    $indiv_active   = "";
                    
                elseif($this->session->userdata('user_pos')== $this->config->item('se')):
                    $corpo 		    = "";
                    $corpo_link 	= "";
                    $corpo_active   = "";
                    
                    $indiv          = 'Individual';
                    $indiv_link     = $this->config->item('custdna_individual');
                    $indiv_active   = $this->config->item('empty');
                endif;
                $add 		        = $this->lang->line('add');
    			$add_link 	        = $this->config->item('custdna_add');
    			$add_active         = $this->config->item('empty');
				
				$prospect           = $this->lang->line('prospect');
				$prospect_link      = $this->config->item('custdna_prospectuser');
				$prospect_active    = $this->config->item('empty'); 

				$import             = $this->lang->line('import');
				$import_link        = $this->config->item('custdna_import');
				$import_active      = $this->config->item('empty');		
				
				$adv_search         = $this->lang->line('adv_search');
    			$adv_search_link    = $this->config->item('custdna_search');
                $adv_search_active  = $this->config->item('empty');
                
				
				$export             = "";
				$export_link        = "";
				$export_active      = "";
				
				$import             = "";
				$import_link        = "";
				$import_active      = "";
				
				$rolling			= "";
    			$rolling_link		= "";
    			$rolling_active     = "";
    		
                $backroll			= "";
    			$backroll_link		= "";
    			$backroll_active    = "";
				
		   else:
				$corpo 		    	= 'Corporate';
                $corpo_link 		= $this->config->item('customerdna');
                $corpo_active   	= $this->config->item('active');
                    
                $indiv          	= 'Individual';
                $indiv_link     	= $this->config->item('custdna_individual');
                $indiv_active   	= $this->config->item('empty');
					
				$add 		        = "";
				$adv_search         = ""; 
				$add_link 	        = "";
				$adv_search_link    = "";
				$add_active	        = "";
				$adv_search_active  = "";
				
				$export             = "";
				$export_link        = "";
				$export_active      = "";
				
				$import             = "";
				$import_link        = "";
				$import_active      = "";
				
				$prospect           = "";
				$prospect_link      = "";
				$prospect_active    = "";
				
				$rolling			= "";
				$rolling_link		= "";
				$rolling_active     = "";
				
				$backroll			= "";
				$backroll_link		= "";
				$backroll_active    = "";
            
        endif;
        
        
        if($this->session->userdata('user_pos')== $this->config->item('ta')):
                    $access = $this->config->item('ta');
        elseif($this->session->userdata('user_pos')== $this->config->item('se')):
                    $access = $this->config->item('se');
        else:
                    $access = "";               
        endif;
		
		if($this->session->userdata('search_dna_corporate')):
			$search = $this->session->userdata('search_dna_corporate');
		else:
			$search = '';
		endif;
		
		$data = array(
                        'title'		=>	$this->lang->line('dnacustomers'),
                        'type'      =>  'Corporate',
                        'table'     =>  array
                                             (
                                                'customers'         =>  $this->customers->getAll($id,'Corporate',$search),
                                                'users'             =>  $this->customers->getUsers($this->config->item('user_dna')),
                                                'status'			=>	$this->status->getActive(),
                                                'groups'			=>	$this->groups->getActive(),
                                                'users'             =>  $this->customers->getUsers($this->config->item('user_dna')),
                                                'sectors'			=>	$this->sectors->getActive(),
                                                'sources'			=>	$this->sources->getActive()
                                             ),
                        'form'      =>  array('action'=>$this->config->item('custdna_pic')),                        
						'action'	=>	'customersdna/crm/groupCorporate/',
						'search'	=>  $search,
						'content'	=> 	'list-new',
                        'access'    =>  $access,
						'menu' 		=> 	array(
												'dashboard_active'	=>	$this->config->item('empty'),
												'contact_active'	=>	$this->config->item('empty'),
                                                'contactdna_active'	=>	$this->config->item('active'),
												'activity_active'	=>	$this->config->item('empty'),
												'job_active'		=>	$this->config->item('empty'),
												'call_active'		=>	$this->config->item('empty'),
												'user_active'		=>	$this->config->item('empty'),
												'report_active'		=>	$this->config->item('empty'),
												'master_active'		=>	$this->config->item('empty'),
												'graphic_active'	=>	$this->config->item('empty'),
												'setting_active'	=>	$this->config->item('empty'),
											 ),
						'tab'		=>	array(
												'tab1'				=>	$corpo,
                                                'tab1_link'			=>	$corpo_link,
												'tab1_active'		=>	$corpo_active,
												'tab2'				=>	$indiv,
                                                'tab2_link'			=>	$indiv_link,
												'tab2_active'		=>	$indiv_active,
												'tab3'				=>	$add,
												'tab3_link'			=>	$add_link,
												'tab3_active'		=>	$add_active,
												'tab4'				=>	$rolling,
												'tab4_link'			=>	$rolling_link,
												'tab4_active'		=>	$rolling_active,
												'tab5'				=>	$adv_search,
                                                'tab5_link'			=>	$adv_search_link,
												'tab5_active'		=>	$adv_search_active,
												'tab6'				=>	"",
                                                'tab6_link'			=>	$export_link,
												'tab6_active'		=>	$export_active,
												'tab7'				=>	$prospect,
                                                'tab7_link'			=>	$prospect_link,
												'tab7_active'		=>	$prospect_active,
												'tab8'				=>	$import,
                                                'tab8_link'			=>	$import_link,
												'tab8_active'		=>	$import_active,
											 )			
					 );
        $this->session->set_userdata('report_type',$data['type']);             
		$this->load->vars($data);
		$this->load->theme('default');
	}
	
	function individual($id=1){
	    
        if($this->session->userdata('user_pos')== $this->config->item('ta')):
            redirect('customersdna/crm/index/',301);
        endif; 
               
	    if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna'))  ):
                $corpo 		    	= 'Corporate';
                $corpo_link 		= $this->config->item('customerdna');
                $corpo_active   	= $this->config->item('empty');
				
				$indiv          	= 'Individual';
                $indiv_link     	= $this->config->item('custdna_individual');
                $indiv_active   	= $this->config->item('active');
				
				$add 		        = $this->lang->line('add');
    			$add_link 	        = $this->config->item('custdna_add');
    			$add_active         = $this->config->item('empty');
    			
    			$adv_search         = $this->lang->line('adv_search');
    			$adv_search_link    = $this->config->item('custdna_search');
                $adv_search_active  = $this->config->item('empty');
                
                $export             = $this->lang->line('export');
    			$export_link        = $this->config->item('custdna_excel');
                $export_active      = $this->config->item('empty');
                
                $import             = $this->lang->line('import');
    			$import_link        = $this->config->item('custdna_import');
                $import_active      = $this->config->item('empty');
                
                
                $prospect           = $this->lang->line('prospect');
    			$prospect_link      = $this->config->item('custdna_prospect');
                $prospect_active    = $this->config->item('empty');
    			
    			$rolling			= "";
    			$rolling_link		= "";
    			$rolling_active     = "";
    			
                $backroll			= "";
    			$backroll_link		= "";
    			$backroll_active    = "";
           elseif(($this->session->userdata('user_group')== $this->config->item('user_dna')) ):
				
                if ($this->session->userdata('user_pos')== $this->config->item('ta')):
                    $corpo 		    = 'Corporate';
                    $corpo_link 	= $this->config->item('customerdna');
                    $corpo_active   = $this->config->item('empty');
                    
                    $indiv          = "";
                    $indiv_link     = "";
                    $indiv_active   = "";
                    
                elseif($this->session->userdata('user_pos')== $this->config->item('se')):
                    $corpo 		    = "";
                    $corpo_link 	= "";
                    $corpo_active   = "";
                    
                    $indiv          = 'Individual';
                    $indiv_link     = $this->config->item('custdna_individual');
                    $indiv_active   = $this->config->item('active');
                endif;
                
                $add 		        = $this->lang->line('add');
    			$add_link 	        = $this->config->item('custdna_add');
    			$add_active         = $this->config->item('empty');
				
				$prospect           = $this->lang->line('prospect');
				$prospect_link      = $this->config->item('custdna_prospectuser');
				$prospect_active    = $this->config->item('empty'); 

				$import             = $this->lang->line('import');
				$import_link        = $this->config->item('custdna_import');
				$import_active      = $this->config->item('empty');		
				
				$adv_search         = $this->lang->line('adv_search');
    			$adv_search_link    = $this->config->item('custdna_search');
                $adv_search_active  = $this->config->item('empty');
				
				$export             = "";
				$export_link        = "";
				$export_active      = "";
				
				$import             = "";
				$import_link        = "";
				$import_active      = "";
				
				$rolling			= "";
    			$rolling_link		= "";
    			$rolling_active     = "";
    		
                $backroll			= "";
    			$backroll_link		= "";
    			$backroll_active    = "";
				
		   else:
				$add 		        = "";
				$adv_search         = ""; 
				$add_link 	        = "";
				$adv_search_link    = "";
				$add_active	        = "";
				$adv_search_active  = "";
				
				$export             = "";
				$export_link        = "";
				$export_active      = "";
				
				$import             = "";
				$import_link        = "";
				$import_active      = "";
				
				$prospect           = $this->lang->line('prospect');
				$prospect_link      = $this->config->item('custdna_prospectuser');
				$prospect_active    = $this->config->item('empty');
				
				$rolling			= "";
				$rolling_link		= "";
				$rolling_active     = "";
				
				$backroll			= "";
				$backroll_link		= "";
				$backroll_active    = "";
            
        endif;
        
        
        
        if($this->session->userdata('user_pos')== $this->config->item('ta')):
                    $access = $this->config->item('ta');
        elseif($this->session->userdata('user_pos')== $this->config->item('se')):
                    $access = $this->config->item('se');
        else:
                    $access = "";               
        endif;
        if($this->session->userdata('search_dna_individual')):
			$search = $this->session->userdata('search_dna_individual');
		else:
			$search = '';
		endif;	
		$data = array(
                        'title'		=>	$this->lang->line('dnacustomers'),
                        'table'     =>  array
                                             (
                                                'customers'         =>  $this->customers->getAll($id,'Individual',$search),
                                                'status'			=>	$this->status->getActive(),
                                                'groups'			=>	$this->groups->getActive(),
                                                'users'             =>  $this->customers->getUsers($this->config->item('user_dna')),
                                                'sectors'			=>	$this->sectors->getActive(),
                                                'sources'			=>	$this->sources->getActive()
  
                                             ),
                        'form'      =>  array('action'=>$this->config->item('custdna_pic')),                        
						'type'      =>  'Individual',
						'action'	=>	'customersdna/crm/groupIndividual/',
						'search'	=>  $this->session->userdata('search_dna_individual'),
                        'content'	=> 	'list-new',
                        'access'    =>  $access,
						'menu' 		=> 	array(
												'dashboard_active'	=>	$this->config->item('empty'),
												'contact_active'	=>	$this->config->item('empty'),
                                                'contactdna_active'	=>	$this->config->item('active'),
												'activity_active'	=>	$this->config->item('empty'),
												'job_active'		=>	$this->config->item('empty'),
												'call_active'		=>	$this->config->item('empty'),
												'user_active'		=>	$this->config->item('empty'),
												'report_active'		=>	$this->config->item('empty'),
												'master_active'		=>	$this->config->item('empty'),
												'graphic_active'	=>	$this->config->item('empty'),
												'setting_active'	=>	$this->config->item('empty'),
											 ),
						'tab'		=>	array(
												'tab1'				=>	$corpo,
                                                'tab1_link'			=>	$corpo_link,
												'tab1_active'		=>	$corpo_active,
												'tab2'				=>	$indiv,
                                                'tab2_link'			=>	$indiv_link,
												'tab2_active'		=>	$indiv_active,
												'tab3'				=>	$add,
												'tab3_link'			=>	$add_link.'Individual/',
												'tab3_active'		=>	$add_active,
												'tab4'				=>	$rolling,
												'tab4_link'			=>	$rolling_link,
												'tab4_active'		=>	$rolling_active,
												'tab5'				=>	$adv_search,
                                                'tab5_link'			=>	$adv_search_link,
												'tab5_active'		=>	$adv_search_active,
												'tab6'				=>	"",
                                                'tab6_link'			=>	$export_link,
												'tab6_active'		=>	$export_active,
												'tab7'				=>	$prospect,
                                                'tab7_link'			=>	$prospect_link,
												'tab7_active'		=>	$prospect_active,
												'tab8'				=>	$import,
                                                'tab8_link'			=>	$import_link,
												'tab8_active'		=>	$import_active,
											 )			
					 );
        $this->session->set_userdata('report_type',$data['type']);               
		$this->load->vars($data);
		$this->load->theme('default');
	}
	
	function groupCorporate(){
		$this->session->set_userdata('search_dna_corporate',$this->input->post('group'));
		/*$this->db->where('id',$this->input->post('group'));
		$Q=$this->db->get('customer_group');
		$row=$Q->row_array();
		$this->session->set_userdata('search_dna_name',$row['group_name']);*/
		redirect('customersdna/crm/index/',301);
	}
	
	function groupIndividual(){
		$this->session->set_userdata('search_dna_individual',$this->input->post('group'));
		/*$this->db->where('id',$this->input->post('group'));
		$Q=$this->db->get('customer_group');
		$row=$Q->row_array();
		$this->session->set_userdata('search_dna_name',$row['group_name']);*/
		redirect('customersdna/crm/individual/',301);
	}
    
    function rolling(){
		$sql ="SELECT * FROM customers WHERE type='Corporate' AND rev2<>'' order by point ASC ";
		$query=$this->db->query($sql);
		$q=$query->result_array();
		$a=1;
		$t=count($q);
		foreach($q as $row):
            $this->db->select('COUNT(customer_id) as totalCustomer');
            $this->db->join('users','users.username=activity_transaction.pic');
			$this->db->where('customer_id',$row['id']);
			$this->db->where('activity_id',3);
            $this->db->where('users.group_id',$this->config->item('user_dna'));
            $this->db->groupby('customer_id');
            $q2=$this->db->get('activity_transaction');
            $val=$q2->row_array();
            if(COUNT($val)>=1):
                $data['point']=$val['totalCustomer'];
                $this->db->where('id',$row['id']);
			    $this->db->update('customers',$data);
            else:
                $this->db->where_not_in('username',$row['rev2']);
                $this->db->where('pos_id',$this->config->item('ta'));
                $this->db->where('group_id',$this->config->item('user_dna'));
                $this->db->where('enabled',1);
                $this->db->where('sales',1);
                $this->db->orderby('RAND()');
                $q3=$this->db->get('users');
                $user=$q3->row_array();
                $value['rev2']=$user['username'];
                $this->db->where('id',$row['id']);
			    $this->db->update('customers',$value);
            endif;
			$a++;
         endforeach;   
		redirect($this->input->server('HTTP_REFERER')); 
	}
    
   	
	
	function import($id=1){
	    if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna'))  ):
                $corpo 		    	= 'Corporate';
                $corpo_link 		= $this->config->item('customerdna');
                $corpo_active   	= $this->config->item('empty');
				
				$indiv          	= 'Individual';
                $indiv_link     	= $this->config->item('custdna_individual');
                $indiv_active   	= $this->config->item('emtpy');
				
				$add 		        = $this->lang->line('add');
    			$add_link 	        = $this->config->item('custdna_add');
    			$add_active         = $this->config->item('empty');
    			
    			$adv_search         = $this->lang->line('adv_search');
    			$adv_search_link    = $this->config->item('custdna_search');
                $adv_search_active  = $this->config->item('empty');
                
                $export             = $this->lang->line('export');
    			$export_link        = $this->config->item('custdna_excel');
                $export_active      = $this->config->item('empty');
                
                $import             = $this->lang->line('import');
    			$import_link        = $this->config->item('custdna_import');
                $import_active      = $this->config->item('active');
                
                
                $prospect           = $this->lang->line('prospect');
    			$prospect_link      = $this->config->item('custdna_prospect');
                $prospect_active    = $this->config->item('empty');
    			
    			$rolling			= "";
    			$rolling_link		= "";
    			$rolling_active     = "";
    			
                $backroll			= "";
    			$backroll_link		= "";
    			$backroll_active    = "";
           elseif(($this->session->userdata('user_group')== $this->config->item('user_dna')) && ($this->session->userdata('user_pos')== $this->config->item('ta')) ):
				$add 		        = $this->lang->line('add');
    			$add_link 	        = $this->config->item('custdna_add');
    			$add_active         = $this->config->item('empty');
				
				$prospect           = $this->lang->line('prospect');
				$prospect_link      = $this->config->item('custdna_prospectuser');
				$prospect_active    = $this->config->item('empty'); 

				$import             = $this->lang->line('import');
				$import_link        = $this->config->item('custdna_import');
				$import_active      = $this->config->item('active');		
				
				$adv_search         = $this->lang->line('adv_search');
    			$adv_search_link    = $this->config->item('custdna_search');
                $adv_search_active  = $this->config->item('empty');
				
				$export             = "";
				$export_link        = "";
				$export_active      = "";
				
				$import             = "";
				$import_link        = "";
				$import_active      = "";
				
				$rolling			= "";
    			$rolling_link		= "";
    			$rolling_active     = "";
    		
                $backroll			= "";
    			$backroll_link		= "";
    			$backroll_active    = "";
				
		   else:
				$add 		        = "";
				$adv_search         = ""; 
				$add_link 	        = "";
				$adv_search_link    = "";
				$add_active	        = "";
				$adv_search_active  = "";
				
				$export             = "";
				$export_link        = "";
				$export_active      = "";
				
				$import             = "";
				$import_link        = "";
				$import_active      = "";
				
				$prospect           = $this->lang->line('prospect');
				$prospect_link      = $this->config->item('custdna_prospectuser');
				$prospect_active    = $this->config->item('empty');
				
				$rolling			= "";
				$rolling_link		= "";
				$rolling_active     = "";
				
				$backroll			= "";
				$backroll_link		= "";
				$backroll_active    = "";
            
        endif;
        
        
        
        if($this->session->userdata('user_pos')== $this->config->item('ta')):
                    $access = $this->config->item('ta');
        elseif($this->session->userdata('user_pos')== $this->config->item('se')):
                    $access = $this->config->item('se');
        else:
                    $access = "";               
        endif;      
		$data = array(
                        'title'		=>	$this->lang->line('import'),
                        'table'     =>  array
                                             (
                                                'customers'         =>  $this->customers->getSearchDNA(),
                                                'users'             =>  $this->customers->getUsers($this->config->item('user_dna')),
												'users_inhouse'     =>  $this->customers->getUsers($this->config->item('user')),
												'status'			=>	$this->status->getActive(),
                                                'groups'			=>	$this->groups->getActive(),
                                                'sectors'			=>	$this->sectors->getActive(),
                                                'sources'			=>	$this->sources->getActive()
                                             ),
                        'form'      =>  array('action'=>$this->config->item('custdna_pic')),                        
						'content'	=> 	'list_import',
                        'access'    =>  $access,
						'menu' 		=> 	array(
												'dashboard_active'	=>	$this->config->item('empty'),
												'contact_active'	=>	$this->config->item('empty'),
                                                'contactdna_active'	=>	$this->config->item('active'),
												'activity_active'	=>	$this->config->item('empty'),
												'job_active'		=>	$this->config->item('empty'),
												'call_active'		=>	$this->config->item('empty'),
												'user_active'		=>	$this->config->item('empty'),
												'report_active'		=>	$this->config->item('empty'),
												'master_active'		=>	$this->config->item('empty'),
												'graphic_active'	=>	$this->config->item('empty'),
												'setting_active'	=>	$this->config->item('empty'),
											 ),
						'tab'		=>	array(
												'tab1'				    =>	'Corporate',
													'tab1_link'			=>	$this->config->item('customerdna'),
													'tab1_active'		=>	$this->config->item('empty'),
													'tab2'				=>	'Individual',
													'tab2_link'			=>	$this->config->item('custdna_individual'),
													'tab2_active'		=>	$this->config->item('empty'),
													'tab3'				=>	$add,
													'tab3_link'			=>	$add_link,
													'tab3_active'		=>	$add_active,
    												'tab4'				=>	$adv_search,
    												'tab4_link'			=>	$adv_search_link,
    												'tab4_active'		=>	$adv_search_active,
    												'tab5'				=>	'',
    												'tab6'				=>	"",
                                                    'tab6_link'			=>	$export_link,
    												'tab6_active'		=>	$export_active,
    												'tab7'				=>	$prospect,
                                                    'tab7_link'			=>	$prospect_link,
												    'tab7_active'		=>	$prospect_active,
    												'tab8'				=>	$import,
                                                    'tab8_link'			=>	$import_link,
    												'tab8_active'		=>	$import_active
											 )			
					 );
		$this->load->vars($data);
		$this->load->theme('default');
	}
	
	function importform(){
		if($this->input->post('user')<>""):
			$id=$this->input->post('id');
			$total=COUNT($id);
			for($i=0;$i<$total;$i++):
				if($total>$i):
					$value['rev2'] = $this->input->post('user');
					$this->db->where('id',$id[$i]);
					$this->db->update('customers',$value);
				endif;
			endfor;
		else:
			$id=$this->input->post('id');
			$total=COUNT($id);
			for($i=0;$i<$total;$i++):
				if($total>$i):
					//$this->db->where('sales','1');
					//$this->db->where('pos_id',$this->config->item('ta'));
					//$this->db->or_where('pos_id',$this->config->item('se'));
					//$this->db->where('group_id',$this->config->item('user_dna'));
					//$this->db->orderby('id','RAND()');
					//$Q=$this->db->get('users');
					$sql =" SELECT u.username ";
					$sql.=" FROM users u ";
					$sql.=" WHERE ";
					$sql.=" sales=1 AND enabled=1 ";
					$sql.=" AND u.group_id=".$this->config->item('user_dna');
					$sql.=" AND (u.pos_id=".$this->config->item('ta')." OR u.pos_id=".$this->config->item('se').")"; 
					$sql.=" ORDER BY RAND() ";
					$Q=$this->db->query($sql);
					$user=$Q->row_array();
					$value['rev2'] = $user['username'];
					$this->db->where('id',$id[$i]);
					$this->db->update('customers',$value);
				endif;
			endfor;
		endif;
		$this->session->set_flashdata('message','<span class="message success"><strong>Success </strong> Success Import Data From Inhouse !</span>');
        redirect($this->input->server('HTTP_REFERER'));
	}
    
    function pic(){
		$sql =" SELECT * ";
        $sql.=" FROM customers  ";
        $sql.=" WHERE rev2<>'' AND rev2='".$this->input->post('old_pic')."' ";
        $sql.=" ORDER BY point ASC";
		$query=$this->db->query($sql);
		$q=$query->result_array();
		foreach($q as $row):
            $this->db->where('id',$row['id']);
			$value['rev']  = $this->input->post('new_pic');
            $value['rev2'] = $this->input->post('new_pic');
            $this->db->update('customers',$value);
         endforeach;   
		redirect($this->input->server('HTTP_REFERER')); 
	}	
    
    
    function addnew($type=''){
        
        if(($this->session->userdata('user_pos')== $this->config->item('se')) && ($type=='') ):
            redirect('customersdna/crm/addnew/Individual',301);
        endif;
         
	    if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('user_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna'))):
            
    		if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna'))):
                $corpo 		    	= 'Corporate';
                $corpo_link 		= $this->config->item('customerdna');
                $corpo_active   	= $this->config->item('empty');
				
				$indiv          	= 'Individual';
                $indiv_link     	= $this->config->item('custdna_individual');
                $indiv_active   	= $this->config->item('emtpy');
				
				$add 		        = $this->lang->line('add');
    			$add_link 	        = $this->config->item('custdna_add');
    			$add_active         = $this->config->item('active');
    			
    			$adv_search         = $this->lang->line('adv_search');
    			$adv_search_link    = $this->config->item('custdna_search');
                $adv_search_active  = $this->config->item('empty');
                
                $export             = $this->lang->line('export');
		        $export_link        = $this->config->item('custdna_excel');
                $export_active      = $this->config->item('empty');
                
                $prospect           = $this->lang->line('prospect');
    			$prospect_link      = $this->config->item('custdna_prospect');
                $prospect_active    = $this->config->item('empty');
                
                $import             = $this->lang->line('import');
    			$import_link        = $this->config->item('custdna_import');
                $import_active      = $this->config->item('empty');
                
            elseif(($this->session->userdata('user_group')== $this->config->item('user_dna'))):
                
                if ($this->session->userdata('user_pos')== $this->config->item('ta')):
                    $corpo 		    = 'Corporate';
                    $corpo_link 	= $this->config->item('customerdna');
                    $corpo_active   = $this->config->item('empty');
                    
                    $indiv          = "";
                    $indiv_link     = "";
                    $indiv_active   = "";
                    
                elseif($this->session->userdata('user_pos')== $this->config->item('se')):
                    $corpo 		    = "";
                    $corpo_link 	= "";
                    $corpo_active   = "";
                    
                    $indiv          = 'Individual';
                    $indiv_link     = $this->config->item('custdna_individual');
                    $indiv_active   = $this->config->item('empty');
                endif;
                
                
                $add 		        = $this->lang->line('add');
    			$add_link 	        = $this->config->item('custdna_add');
    			$add_active         = $this->config->item('active');
    			
    			$adv_search         = $this->lang->line('adv_search');
    			$adv_search_link    = $this->config->item('custdna_search');
                $adv_search_active  = $this->config->item('empty');
                
                $export             = "";
		        $export_link        = "";
                $export_active      = "";
                
                $import             = "";
    			$import_link        = "";
                $import_active      = "";
                
                $prospect           = $this->lang->line('prospect');
				$prospect_link      = $this->config->item('custdna_prospectuser');
				$prospect_active    = $this->config->item('empty'); 
       
            else:
                $add 		        = "";
                $adv_search         = ""; 
    			$add_link 	        = "";
                $adv_search_link    = "";
    			$add_active	        = "";
                $adv_search_active  = "";
                
                $export             = "";
		        $export_link        = "";
                $export_active      = "";
                
                $import             = "";
    			$import_link        = "";
                $import_active      = "";
                
                $prospect           = "";
				$prospect_link      = "";
				$prospect_active    = ""; 
                
            endif; 
               
    		$data = array(
    						'title'		=>	$this->lang->line('add'),
    						'table'		=>	array(
    												'status'			=>	$this->status->getActive(),
                                                    'groups'			=>	$this->groups->getActive(),
                                                    'value'             =>  "",
                                                    'users'             =>  $this->customers->getUsers($this->config->item('user_dna')),
                                                    'sectors'			=>	$this->sectors->getActive(),
                                                    'sources'			=>	$this->sources->getActive()
    											 ),
                            'form'      =>  array('action'=>$this->config->item('custdna_save')),                     
    						'type'      =>  $type,    
                            'content'	=> 	'form',
    						'menu' 		=> 	array(
    												'dashboard_active'	=>	$this->config->item('empty'),
    												'contact_active'	=>	$this->config->item('empty'),
                                                    'contactdna_active'	=>	$this->config->item('active'),
    												'activity_active'	=>	$this->config->item('empty'),
    												'job_active'		=>	$this->config->item('empty'),
    												'call_active'		=>	$this->config->item('empty'),
    												'user_active'		=>	$this->config->item('empty'),
    												'report_active'		=>	$this->config->item('empty'),
    												'master_active'		=>	$this->config->item('empty'),
    												'graphic_active'	=>	$this->config->item('empty'),
    												'setting_active'	=>	$this->config->item('empty'),
    											 ),
    						'tab'		=>	array(
    												'tab1'				=>	$corpo,
													'tab1_link'			=>	$corpo_link,
													'tab1_active'		=>	$corpo_active,
													'tab2'				=>	$indiv,
													'tab2_link'			=>	$indiv_link,
													'tab2_active'		=>	$indiv_active,
													'tab3'				=>	$add,
													'tab3_link'			=>	$add_link,
													'tab3_active'		=>	$add_active,
    												'tab4'				=>	$adv_search,
    												'tab4_link'			=>	$adv_search_link,
    												'tab4_active'		=>	$adv_search_active,
    												'tab5'				=>	'',
    												'tab6'				=>	"",
                                                    'tab6_link'			=>	$export_link,
    												'tab6_active'		=>	$export_active,
    												'tab7'				=>	$prospect,
                                                    'tab7_link'			=>	$prospect_link,
												    'tab7_active'		=>	$prospect_active,
    												'tab8'				=>	$import,
                                                    'tab8_link'			=>	$import_link,
    												'tab8_active'		=>	$import_active
    											 )			
    					 );
    		$this->load->vars($data);
    		$this->load->theme('default');
         else:
            redirect($this->config->item('customerdna'));
        endif;    
	}
    
    function savecust(){
        if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('user_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna')) ):
            
            if($this->input->post('save')):
                $val=count($this->customers->getCek());
                if($val < 1):
                    $this->customers->getSave();
                    $this->session->set_flashdata('message','<span class="message success"><strong>Success </strong>message - '.$this->lang->line('m_save').'  </span>');
                    redirect($this->input->server('HTTP_REFERER'));
                else:
                    $this->session->set_flashdata('message','<span class="message error"><strong>Success</strong>message - '.$this->lang->line('m_duplicate').'  </span>');
                    redirect($this->input->server('HTTP_REFERER'));
                endif;
            endif;    
        else:
            redirect($this->config->item('customerdna'));
        endif;
    }
    
    function editcust($id){
	    if(!$this->session->userdata('menu1')==1):
			redirect($this->config->item('customerdna'));
		endif;
        
        $this->db->where('id',$id);
        $Q=$this->db->get('customers');
        $type=$Q->row_array();
        $type=$type['type'];
        
        if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna'))):
                $corpo 		    	= 'Corporate';
                $corpo_link 		= $this->config->item('customerdna');
                $corpo_active   	= $this->config->item('empty');
				
				$indiv          	= 'Individual';
                $indiv_link     	= $this->config->item('custdna_individual');
                $indiv_active   	= $this->config->item('emtpy');
				
				$add 		        = $this->lang->line('add');
    			$add_link 	        = $this->config->item('custdna_add');
    			$add_active         = $this->config->item('empty');
    			
    			$adv_search         = $this->lang->line('adv_search');
    			$adv_search_link    = $this->config->item('custdna_search');
                $adv_search_active  = $this->config->item('empty');
                
                $export             = $this->lang->line('export');
		        $export_link        = $this->config->item('custdna_excel');
                $export_active      = $this->config->item('empty');
                
                $import             = $this->lang->line('import');
    			$import_link        = $this->config->item('custdna_import');
                $import_active      = $this->config->item('empty');
                
            elseif(($this->session->userdata('user_group')== $this->config->item('user_dna')) && ($this->session->userdata('user_pos')== $this->config->item('ta'))):
                $add 		        = $this->lang->line('add');
    			$add_link 	        = $this->config->item('custdna_add');
    			$add_active         = $this->config->item('empty');
    			
    			$adv_search         = "";
    			$adv_search_link    = "";
                $adv_search_active  = "";
                
                $export             = "";
		        $export_link        = "";
                $export_active      = "";
                
                $import             = "";
    			$import_link        = "";
                $import_active      = "";
       
            else:
                $add 		        = "";
                $adv_search         = ""; 
    			$add_link 	        = "";
                
                $adv_search         = $this->lang->line('adv_search');
    			$adv_search_link    = $this->config->item('custdna_search');
                $adv_search_active  = $this->config->item('empty');
                
                $export             = "";
		        $export_link        = "";
                $export_active      = "";
                
                $import             = "";
    			$import_link        = "";
                $import_active      = "";
                
            endif;    
        
        if(!$id):
            $this->session->set_flashdata('message','<span class="message error"><strong>Error</strong>message - '.$this->lang->line('m_wrong').'  </span>');    
            redirect($this->config->item('customerdna'));
        endif;
           
		$data = array(
						'title'		=>	$this->lang->line('edit').' '.$id,
						'table'		=>	array(
                                                'value'				=>	$this->customers->getData($id),
                                                'status'			=>	$this->status->getActive(),
                                                'groups'			=>	$this->groups->getActive(),
                                                'sectors'			=>	$this->sectors->getActive(),
                                                'sources'			=>	$this->sources->getActive()
											 ),
                        'form'      =>  array('action'=>$this->config->item('custdna_update')),                     
						'content'	=> 	'form',
                        'type'      =>  $type,
						'menu' 		=> 	array(
												'dashboard_active'	=>	$this->config->item('empty'),
												'contact_active'	=>	$this->config->item('empty'),
                                                'contactdna_active'	=>	$this->config->item('active'),
												'activity_active'	=>	$this->config->item('empty'),
												'job_active'		=>	$this->config->item('empty'),
												'call_active'		=>	$this->config->item('empty'),
												'user_active'		=>	$this->config->item('empty'),
												'report_active'		=>	$this->config->item('empty'),
												'master_active'		=>	$this->config->item('empty'),
												'graphic_active'	=>	$this->config->item('empty'),
												'setting_active'	=>	$this->config->item('empty'),
											 ),
						'tab'		=>	array(
											    'tab1'				=>	'Corporate',
                                                'tab1_link'		    =>	$this->config->item('customerdna'),
                                                'tab1_active'		=>	$this->config->item('empty'),
                                                'tab2'				=>	'Individual',
                                                'tab2_link'		    =>	$this->config->item('custdna_individual'),
                                                'tab2_active'		=>	$this->config->item('empty'),
                                                'tab3'				=>	$add,
                                                'tab3_link'		    =>	$add_link,
                                                'tab3_active'		=>	$add_active,
                                                'tab4'			    =>	$adv_search,
                                                'tab4_link'	    	=>	$adv_search_link,
                                                'tab4_active'	    =>	$adv_search_active,
                                                'tab5'			    =>	'',
                                                'tab6'			    =>	"",
                                                'tab6_link'		    =>	$export_link,
                                                'tab6_active'	    =>	$export_active,
                                                'tab7'				=>	$this->lang->line('edit'),
                                                'tab7_link'		    =>	$this->config->item('custdna_edit').$id,
					                            'tab7_active'		=>	$this->config->item('active'),
                                                'tab8'			    =>	$import,
                                                'tab8_link'		    =>	$import_link,
                                                'tab8_active'	    =>	$import_active
											 )			
					 );
		$this->load->vars($data);
		$this->load->theme('default');
	}
    
    function updatecust(){
        if(!$this->session->userdata('menu1')==1):
			redirect($this->config->item('customerdna'));
		endif;
        
        if($this->input->post('save')):
                $this->customers->getUpdate();
                $this->session->set_flashdata('message','<span class="message success"><strong>Success</strong>message - '.$this->lang->line('m_update').'  </span>');
                redirect($this->input->server('HTTP_REFERER')); 
        endif;
    }
    
     function deletecust($id){
        if($this->session->userdata('user_group')!= $this->config->item('admin_dna') ):
            redirect($this->config->item('customerdna'));
        endif;
        $this->customers->getRemove($id);
        $this->session->set_flashdata('message','<span class="message success"><strong>Succes </strong>message - '.$this->lang->line('m_delete').'  </span>');
        redirect($this->input->server('HTTP_REFERER'));
        
    }
	
	function deleteAll($id=''){
        if($this->session->userdata('user_group')!= $this->config->item('admin_dna') ):
            redirect($this->config->item('customerdna'));
        endif;
        $this->customers->getRemoveImport();
        $this->session->set_flashdata('message','<span class="message success"><strong>Succes </strong>message - '.$this->lang->line('m_delete').'  </span>');
        redirect($this->input->server('HTTP_REFERER'));
        
    }
    
    function deleteselectedcust(){
        if($this->session->userdata('user_group')!= $this->config->item('admin_dna') ):
            redirect($this->config->item('customerdna'));
        endif;
        $this->customers->getRemoveProspectSelected();
        $this->session->set_flashdata('message','<span class="message success"><strong>Succes </strong>message - '.$this->lang->line('m_delete').'  </span>');
        redirect($this->input->server('HTTP_REFERER'));
    }
    
    function deleteuserselectedcust(){
        if($this->session->userdata('user_group')!= $this->config->item('admin_dna') ):
            redirect($this->config->item('customerdna'));
        endif;
        $this->customers->getRemoveProspectUserSelected();
        $this->session->set_flashdata('message','<span class="message success"><strong>Succes </strong>message - '.$this->lang->line('m_delete').'  </span>');
        redirect($this->input->server('HTTP_REFERER'));
    }
    
    function savesect(){
        if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna'))):
            
            if($this->input->post('save')):
                $val=count($this->sectors->getCek());
                if($val<1):
                    $this->sectors->getSave();
                    $this->session->set_flashdata('message2','<span class="message success"><strong>Success</strong>message - '.$this->lang->line('m_save').'  </span>');
                    redirect($this->input->server('HTTP_REFERER'));
                else:
                    $this->session->set_flashdata('message2','<span class="message error"><strong>Error </strong>message - '.$this->lang->line('m_duplicate').'  </span>');
                    redirect($this->input->server('HTTP_REFERER'));
                endif;
            endif;
            
         else:
            redirect($this->config->item('customerdna'));
         endif;   
    }
    
    function updatesect(){
        if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna'))):
           
            if($this->input->post('save')):
                    $this->sectors->getUpdate();
                    $this->session->set_flashdata('message2','<span class="message success"><strong>Succes </strong>message - '.$this->lang->line('m_update').'  </span>');                     
        
            elseif($this->input->post('delete')):  
                    $this->sectors->getRemove();    
                    $this->session->set_flashdata('message2','<span class="message success"><strong>Succes </strong>message - '.$this->lang->line('m_delete').'  </span>');     
            endif;
            redirect($this->input->server('HTTP_REFERER'));
         
        else:
            redirect($this->config->item('customerdna'));
        endif;   
    } 
    
    function savegroup(){
        if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna'))):
           
            if($this->input->post('save')):
                $val=count($this->groups->getCek());
                if($val<1):
                    $this->groups->getSave();
                    $this->session->set_flashdata('message3','<span class="message success"><strong>Success</strong>message - '.$this->lang->line('m_save').'  </span>');
                    redirect($this->input->server('HTTP_REFERER'));
                else:
                    $this->session->set_flashdata('message3','<span class="message error"><strong>Error </strong>message - '.$this->lang->line('m_duplicate').'  </span>');
                    redirect($this->input->server('HTTP_REFERER'));
                endif;
            endif;
           
        else:
            redirect($this->config->item('customerdna'));
        endif;      
    }
    
    function updategroup(){
        if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna'))):
          
            if($this->input->post('save')):
                    $this->groups->getUpdate();
                    $this->session->set_flashdata('message3','<span class="message success"><strong>Succes </strong>message - '.$this->lang->line('m_update').'  </span>');                     
                 
                elseif($this->input->post('delete')) :  
                    $this->groups->getRemove();    
                    $this->session->set_flashdata('message3','<span class="message success"><strong>Succes </strong>message - '.$this->lang->line('m_delete').'  </span>');     
                endif;
            redirect($this->input->server('HTTP_REFERER')); 
        
        else:
            redirect($this->config->item('customerdna'));
        endif;       
    } 
    
    function savesource(){
        if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna'))):
          
           
            if($this->input->post('save')):
                $val=count($this->sources->getCek());
                if($val<1):
                    $this->sources->getSave();
                    $this->session->set_flashdata('message4','<span class="message success"><strong>Success</strong>message - '.$this->lang->line('m_save').'  </span>');
                    redirect($this->input->server('HTTP_REFERER'));
                else:
                    $this->session->set_flashdata('message4','<span class="message error"><strong>Error </strong>message - '.$this->lang->line('m_duplicate').'  </span>');
                    redirect($this->input->server('HTTP_REFERER'));
                endif;
            endif;
            
          else:
            redirect($this->config->item('customerdna'));
          endif;     
    }
    
    function updatesource(){
        if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna'))):
          
            if($this->input->post('save')):
                    $this->sources->getUpdate();
                    $this->session->set_flashdata('message4','<span class="message success"><strong>Succes </strong>message - '.$this->lang->line('m_update').'  </span>');                     
            elseif($this->input->post('delete')) :  
                    $this->sources->getRemove();    
                    $this->session->set_flashdata('message4','<span class="message success"><strong>Succes </strong>message - '.$this->lang->line('m_delete').'  </span>');     
            endif;
            redirect($this->input->server('HTTP_REFERER'));
        else:
            redirect($this->config->item('customerdna'));
        endif;   
    }
    
    function savestatus(){
        if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna'))):
          
            if($this->input->post('save')):
                $val=count($this->status->getCek());
                if($val<1):
                    $this->status->getSave();
                    $this->session->set_flashdata('message5','<span class="message success"><strong>Success</strong>message - '.$this->lang->line('m_save').'  </span>');
                    redirect($this->input->server('HTTP_REFERER'));
                 else:
                    $this->session->set_flashdata('message5','<span class="message error"><strong>Error </strong>message - '.$this->lang->line('m_duplicate').'  </span>');
                    redirect($this->input->server('HTTP_REFERER'));
                endif;
            endif;
            
        else:
            redirect($this->config->item('customerdna'));
        endif; 
    }
    
    function updatestatus(){
        if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna'))):
         
            if($this->input->post('save')):
                    $this->status->getUpdate();
                    $this->session->set_flashdata('message5','<span class="message success"><strong>Succes </strong>message - '.$this->lang->line('m_update').'  </span>');                     
                 
            elseif($this->input->post('delete')):  
                    $this->status->getRemove();    
                    $this->session->set_flashdata('message5','<span class="message success"><strong>Succes </strong>message - '.$this->lang->line('m_delete').'  </span>');     
            endif;
            redirect($this->input->server('HTTP_REFERER'));
         else:
            redirect($this->config->item('customerdna'));
         endif;     
    }
	
	
    function searchcust(){
        if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('user_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna'))):
         
            
    	    if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('user_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna')) ):
                $add 		        = $this->lang->line('add');
                $adv_search         = $this->lang->line('adv_search');
    			$add_link 	        = $this->config->item('custdna_add');
                $adv_search_link    = $this->config->item('custdna_search');
    			$add_active         = $this->config->item('empty');
                $adv_search_active  = $this->config->item('active');
                $export             = $this->lang->line('export');
		        $export_link        = $this->config->item('custdna_excel');
                $export_active      = $this->config->item('empty');
				
				$rolling			= "";
				$rolling_link		= "";
				$rolling_active     = "";
				
				$backroll			= "";
				$backroll_link		= "";
			    $backroll_active    = "";
                
                $prospect           = $this->lang->line('prospect');
    			$prospect_link      = $this->config->item('custdna_prospect');
                $prospect_active    = $this->config->item('empty');
                
                $import             = $this->lang->line('import');
    			$import_link        = $this->config->item('custdna_import');
                $import_active      = $this->config->item('empty');
			
            else:
                $add 		        = "";
                $adv_search         = ""; 
    			$add_link 	        = "";
                
                $adv_search_link    = "";
    			$add_active	        = "";
                $adv_search_active  = "";
                
                $export             = "";
		        $export_link        = "";
                $export_active      = "";
				
				$rolling			= "";
				$rolling_link		= "";
				$rolling_active     = "";
				
				$backroll			= "";
				$backroll_link		= "";
				$backroll_active    = "";
                
                $import             = "";
    			$import_link        = "";
                $import_active      = "";
            endif;
            
            if($this->session->userdata('user_pos')== $this->config->item('ta')):
                        $access = $this->config->item('ta');
            elseif($this->session->userdata('user_pos')== $this->config->item('se')):
                        $access = $this->config->item('se');
            else:
                        $access = "";               
            endif;      
                  
    		$data = array(
                            'title'		=>	$this->lang->line('adv_search'),
                            'table'     =>  array
                                                 (
                                                    'customers'         =>  $this->customers->getSearch(),
                                                    'status'			=>	$this->status->getActive(),
                                                    'groups'			=>	$this->groups->getActive(),
                                                    'users'             =>  $this->customers->getUsers($this->config->item('user_dna')),
                                                    'sectors'			=>	$this->sectors->getActive(),
                                                    'sources'			=>	$this->sources->getActive()
                                                 ),
                            'access'    =>  $access,                     
    						'content'	=> 	'list',
    						'menu' 		=> 	array(
    												'dashboard_active'	=>	$this->config->item('empty'),
    												'contact_active'	=>	$this->config->item('empty'),
                                                    'contactdna_active'	=>	$this->config->item('active'),
    												'activity_active'	=>	$this->config->item('empty'),
    												'job_active'		=>	$this->config->item('empty'),
    												'call_active'		=>	$this->config->item('empty'),
    												'user_active'		=>	$this->config->item('empty'),
    												'report_active'		=>	$this->config->item('empty'),
    												'master_active'		=>	$this->config->item('empty'),
    												'graphic_active'	=>	$this->config->item('empty'),
    												'setting_active'	=>	$this->config->item('empty'),
    											 ),
    						'tab'		=>	array(
    												'tab1'				=>	'Corporate',
													'tab1_link'			=>	$this->config->item('customerdna'),
													'tab1_active'		=>	$this->config->item('empty'),
													'tab2'				=>	'Individual',
													'tab2_link'			=>	$this->config->item('custdna_individual'),
													'tab2_active'		=>	$this->config->item('empty'),
													'tab3'				=>	$add,
													'tab3_link'			=>	$add_link,
													'tab3_active'		=>	$add_active,
    												'tab4'				=>	$adv_search,
    												'tab4_link'			=>	$adv_search_link,
    												'tab4_active'		=>	$adv_search_active,
    												'tab5'				=>	'',
    												'tab6'				=>	"",
                                                    'tab6_link'			=>	$export_link,
    												'tab6_active'		=>	$export_active,
    												'tab7'				=>	$prospect,
                                                    'tab7_link'			=>	$prospect_link,
												    'tab7_active'		=>	$prospect_active,
    												'tab8'				=>	$import,
                                                    'tab8_link'			=>	$import_link,
    												'tab8_active'		=>	$import_active
    											 )			
    					 );
    		$this->load->vars($data);
    		$this->load->theme('default');
        else:
            redirect($this->config->item('customerdna'));
        endif;      
	}
    
    function viewcust($id){
        if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna')) ):
                $add 		        = $this->lang->line('add');
                $adv_search         = $this->lang->line('adv_search');
    			$add_link 	        = $this->config->item('custdna_add');
                $adv_search_link    = $this->config->item('custdna_search');
    			$add_active         = $this->config->item('empty');
                $adv_search_active  = $this->config->item('empty');
                $export             = $this->lang->line('export');
		        $export_link        = $this->config->item('custdna_excel');
                $export_active      = $this->config->item('empty');
				
				$rolling			= "";
				$rolling_link		= "";
				$rolling_active     = "";
				
				$backroll			= "";
				$backroll_link		= "";
			    $backroll_active    = "";
                
                $import             = $this->lang->line('import');
    			$import_link        = $this->config->item('custdna_import');
                $import_active      = $this->config->item('empty');
			
            else:
                $add 		        = "";
                $adv_search         = ""; 
    			$add_link 	        = "";
                $adv_search_link    = "";
    			$add_active	        = "";
                $adv_search_active  = "";
                $export             = "";
		        $export_link        = "";
                $export_active      = "";
				
				$rolling			= "";
				$rolling_link		= "";
				$rolling_active     = "";
				
				$backroll			= "";
				$backroll_link		= "";
				$backroll_active    = "";
                
                $import             = "";
    			$import_link        = "";
                $import_active      = "";
            endif;  
        
        if(!$id){
            $this->session->set_flashdata('message','<span class="message error"><strong>Error</strong>message - '.$this->lang->line('m_wrong').'  </span>');    
            redirect($this->config->item('customerdna'));
        }
           
		$data = array(
						'title'		=>	$this->lang->line('view'),
						'table'		=>	array(
                                                'value'				=>	$this->customers->getData($id),
                                                'activity'			=>	$this->customers->getLastActivity($id),
                                                'jobs'			    =>	$this->customers->getLastJob($id),
											 ),
                        'form'      =>  array('action'=>$this->config->item('cust_update')),                     
						'content'	=> 	'view',
						'menu' 		=> 	array(
												'dashboard_active'	=>	$this->config->item('empty'),
												'contact_active'	=>	$this->config->item('empty'),
                                                'contactdna_active'	=>	$this->config->item('active'),
												'activity_active'	=>	$this->config->item('empty'),
												'job_active'		=>	$this->config->item('empty'),
												'call_active'		=>	$this->config->item('empty'),
												'user_active'		=>	$this->config->item('empty'),
												'report_active'		=>	$this->config->item('empty'),
												'master_active'		=>	$this->config->item('empty'),
												'graphic_active'	=>	$this->config->item('empty'),
												'setting_active'	=>	$this->config->item('empty'),
											 ),
						'tab'		=>	array(
											     'tab1'				=>	'Corporate',
                                                 'tab1_link'		=>	$this->config->item('customerdna'),
						                         'tab1_active'		=>	$this->config->item('empty'),
						                         'tab2'				=>	'Individual',
					                             'tab2_link'		=>	$this->config->item('custdna_individual'),
						                         'tab2_active'		=>	$this->config->item('empty'),
						                         'tab3'				=>	$add,
						                         'tab3_link'		=>	$add_link,
					                             'tab3_active'		=>	$add_active,
						                         'tab4'			    =>	$adv_search,
						                         'tab4_link'		=>	$adv_search_link,
						                         'tab4_active'	    =>	$adv_search_active,
						                         'tab5'			    =>	'',
						                         'tab6'			    =>	"",
                                                 'tab6_link'		=>	$export_link,
					                             'tab6_active'	    =>	$export_active,
					                             'tab7'				=>	$this->lang->line('view'),
                                                 'tab7_link'		=>	$this->config->item('custdna_view').$id,
												 'tab7_active'		=>	$this->config->item('active'),
						                         'tab8'			    =>	$import,
                                                 'tab8_link'		=>	$import_link,
						                         'tab8_active'	    =>	$import_active
											 )			
					 );
		$this->load->vars($data);
		$this->load->theme('default');
        
	}
    
    
    function prospect($id=''){
        
	    if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna')) ):
            $add 		        = $this->lang->line('add');
			$add_link 	        = $this->config->item('custdna_add');
			$add_active         = $this->config->item('empty');
			
			$adv_search         = $this->lang->line('adv_search');
			$adv_search_link    = $this->config->item('custdna_search');
            $adv_search_active  = $this->config->item('empty');
            
            $export             = $this->lang->line('export');
			$export_link        = $this->config->item('custdna_excel');
            $export_active      = $this->config->item('empty');
            
            $import             = $this->lang->line('import');
			$import_link        = $this->config->item('custdna_import');
            $import_active      = $this->config->item('empty');
            
            
            $prospect           = $this->lang->line('prospect');
			$prospect_link      = $this->config->item('custdna_prospect');
            $prospect_active    = $this->config->item('active');
			
			$rolling			= "";
			$rolling_link		= "";
			$rolling_active     = "";
			
			$backroll			= $this->lang->line('backrolling');
			$backroll_link		= $this->config->item('custdna_backrolling');
			$backroll_active    = $this->config->item('empty');
            
        else:
            $add 		        = "";
            $adv_search         = ""; 
			$add_link 	        = "";
            $adv_search_link    = "";
			$add_active	        = "";
            $adv_search_active  = "";
            
            $export             = "";
			$export_link        = "";
            $export_active      = "";
            
            $import             = "";
			$import_link        = "";
            $import_active      = "";
            
            $prospect           = $this->lang->line('prospect');
			$prospect_link      = $this->config->item('custdna_prospect');
            $prospect_active    = $this->config->item('active');
            
			$rolling			= "";
			$rolling_link		= "";
			$rolling_active     = "";
			
			$backroll			= "";
			$backroll_link		= "";
			$backroll_active    = "";
            
        endif;
        
        if($this->session->userdata('user_pos')== $this->config->item('ta')):
                    $access = $this->config->item('ta');
        elseif($this->session->userdata('user_pos')== $this->config->item('se')):
                    $access = $this->config->item('se');
        else:
                    $access = "";               
        endif;
        
        $filePath  = './crm-media/csv/customers.csv';
        if(file_exists($filePath)):
            $filePath=$filePath;
        else:
            $filePath="";
        endif;
        
              
		$data = array(
                        'title'		=>	$this->lang->line('prospect'),
                        'table'     =>  array
                                             (
                                                'customers'         =>  $this->customers->getProspect(),
                                                'prospects'         =>  $this->customers->getProspectUsers($id),
                                                'users'	            =>  $this->customers->getUserJob()
                                                //'file'              =>  $filePath,   
                                                //'csv'               =>  $this->csvreader->parse_file($filePath) 
                                             ),
						'content'	=> 	'list',
                        'access'    =>  $access,
						'menu' 		=> 	array(
												'dashboard_active'	=>	$this->config->item('empty'),
												'contact_active'	=>	$this->config->item('empty'),
                                                'contactdna_active'	=>	$this->config->item('active'),
												'activity_active'	=>	$this->config->item('empty'),
												'job_active'		=>	$this->config->item('empty'),
												'call_active'		=>	$this->config->item('empty'),
												'user_active'		=>	$this->config->item('empty'),
												'report_active'		=>	$this->config->item('empty'),
												'master_active'		=>	$this->config->item('empty'),
												'graphic_active'	=>	$this->config->item('empty'),
												'setting_active'	=>	$this->config->item('empty'),
											 ),
						'tab'		=>	array(
												'tab1'				=>	'Corporate',
												'tab1_link'			=>	$this->config->item('customerdna'),
												'tab1_active'		=>	$this->config->item('empty'),
												'tab2'				=>	'Individual',
												'tab2_link'			=>	$this->config->item('custdna_individual'),
												'tab2_active'		=>	$this->config->item('empty'),
												'tab3'				=>	$add,
												'tab3_link'			=>	$add_link,
												'tab3_active'		=>	$add_active,
												'tab4'				=>	$adv_search,
												'tab4_link'			=>	$adv_search_link,
												'tab4_active'		=>	$adv_search_active,
												'tab5'				=>	'',
												'tab6'				=>	"",
                                                'tab6_link'			=>	$export_link,
												'tab6_active'		=>	$export_active,
												'tab7'				=>	$prospect,
                                                'tab7_link'			=>	$prospect_link,
								                'tab7_active'		=>	$prospect_active,
												'tab8'				=>	$import,
                                                'tab8_link'			=>	$import_link,
												'tab8_active'		=>	$import_active
											 )			
					 );
		$this->load->vars($data);
		$this->load->theme('default');
	}
	
	function prospectuser($id=''){
        
	    if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna')) ):
            $add 		        = $this->lang->line('add');
			$add_link 	        = $this->config->item('custdna_add');
			$add_active         = $this->config->item('empty');
			
			$adv_search         = $this->lang->line('adv_search');
			$adv_search_link    = $this->config->item('custdna_search');
            $adv_search_active  = $this->config->item('empty');
            
            $export             = $this->lang->line('export');
			$export_link        = $this->config->item('custdna_excel');
            $export_active      = $this->config->item('empty');
            
            $import             = $this->lang->line('import');
			$import_link        = $this->config->item('custdna_import');
            $import_active      = $this->config->item('empty');
            
            
            $prospect           = $this->lang->line('prospect');
			$prospect_link      = $this->config->item('custdna_prospectuser');
            $prospect_active    = $this->config->item('active');
			
			$rolling			= $this->lang->line('rolling');
			$rolling_link		= $this->config->item('custdna_rolling');
			$rolling_active     = $this->config->item('empty');
            
			$backroll			= $this->lang->line('backrolling');
			$backroll_link		= $this->config->item('custdna_backrolling');
			$backroll_active    = $this->config->item('empty');
			
        else:
            if ($this->session->userdata('user_pos')== $this->config->item('ta')):
                    $corpo 		    = 'Corporate';
                    $corpo_link 	= $this->config->item('customerdna');
                    $corpo_active   = $this->config->item('empty');
                    
                    $indiv          = "";
                    $indiv_link     = "";
                    $indiv_active   = "";
                    
            elseif($this->session->userdata('user_pos')== $this->config->item('se')):
                    $corpo 		    = "";
                    $corpo_link 	= "";
                    $corpo_active   = "";
                    
                    $indiv          = 'Individual';
                    $indiv_link     = $this->config->item('custdna_individual');
                    $indiv_active   = $this->config->item('empty');
            endif;
                
            $add 		        = $this->lang->line('add');
			$add_link 	        = $this->config->item('custdna_add');
			$add_active         = $this->config->item('empty');
            
            $adv_search         = ""; 
            $adv_search_link    = "";
            $adv_search_active  = "";
            
            $export             = "";
			$export_link        = "";
            $export_active      = "";
            
            $import             = "";
			$import_link        = "";
            $import_active      = "";
            
            $prospect           = $this->lang->line('prospect');
			$prospect_link      = $this->config->item('custdna_prospectuser');
            $prospect_active    = $this->config->item('active');
			
			$rolling			= "";
			$rolling_link		= "";
			$rolling_active     = "";
            
			$backroll			= "";
			$backroll_link		= "";
			$backroll_active    = "";
            
        endif;
        
        if($this->session->userdata('user_pos')== $this->config->item('ta')):
                    $access = $this->config->item('ta');
        elseif($this->session->userdata('user_pos')== $this->config->item('se')):
                    $access = $this->config->item('se');
        else:
                    $access = "";               
        endif;
        
        $filePath  = './crm-media/csv/customers.csv';
        if(file_exists($filePath)):
            $filePath=$filePath;
        else:
            $filePath="";
        endif;
        
              
		$data = array(
                        'title'		=>	$this->lang->line('prospect'),
                        'table'     =>  array
                                             (
                                                //'customers'         =>  $this->customers->getProspect(),
                                                'prospects'         =>  $this->customers->getProspectUsers($this->session->userdata('user_id')),
                                                'users'	            =>  $this->customers->getUserJob()
                                                //'file'              =>  $filePath,   
                                                //'csv'               =>  $this->csvreader->parse_file($filePath) 
                                             ),
						'content'	=> 	'list_prospect',
                        'access'    =>  $access,
						'menu' 		=> 	array(
												'dashboard_active'	=>	$this->config->item('empty'),
												'contact_active'	=>	$this->config->item('empty'),
                                                'contactdna_active'	=>	$this->config->item('active'),
												'activity_active'	=>	$this->config->item('empty'),
												'job_active'		=>	$this->config->item('empty'),
												'call_active'		=>	$this->config->item('empty'),
												'user_active'		=>	$this->config->item('empty'),
												'report_active'		=>	$this->config->item('empty'),
												'master_active'		=>	$this->config->item('empty'),
												'graphic_active'	=>	$this->config->item('empty'),
												'setting_active'	=>	$this->config->item('empty'),
											 ),
						'tab'		=>	array(
												'tab1'				=>	$corpo,
												'tab1_link'			=>	$corpo_link,
												'tab1_active'		=>	$corpo_active,
												'tab2'				=>	$indiv,
												'tab2_link'			=>	$indiv_link,
												'tab2_active'		=>	$indiv_active,
												'tab3'				=>	$add,
												'tab3_link'			=>	$add_link,
												'tab3_active'		=>	$add_active,
												'tab4'				=>	$adv_search,
												'tab4_link'			=>	$adv_search_link,
												'tab4_active'		=>	$adv_search_active,
												'tab5'				=>	'',
												'tab6'				=>	"",
                                                'tab6_link'			=>	$export_link,
												'tab6_active'		=>	$export_active,
												'tab7'				=>	$prospect,
                                                'tab7_link'			=>	$prospect_link,
								                'tab7_active'		=>	$prospect_active,
												'tab8'				=>	$import,
                                                'tab8_link'			=>	$import_link,
												'tab8_active'		=>	$import_active
											 )			
					 );
		$this->load->vars($data);
		$this->load->theme('default');
	}
    
    function viewprospect($id){
        if(($this->session->userdata('user_group')== $this->config->item('admin_dna')) || ($this->session->userdata('user_group')== $this->config->item('co_admin_dna')) ):
            $add 		        = $this->lang->line('add');
			$add_link 	        = $this->config->item('custdna_add');
			$add_active = $this->config->item('empty');
            
            $prospect           = $this->lang->line('prospect');
			$prospect_link      = $this->config->item('custdna_prospect');
            $prospect_active    = $this->config->item('empty');
            
            $import             = $this->lang->line('import');
			$import_link        = $this->config->item('custdna_import');
            $import_active      = $this->config->item('empty');
            
        else:
            $add 		        = ""; 
			$add_link 	        = "";
			$add_active	        = "";
            
            $prospect           = "";
			$prospect_link      = "";
            $prospect_active    = "";
            
            $import             = "";
			$import_link        = "";
			$import_active      = "";
                
        endif;      
        
        if(!$id){
            $this->session->set_flashdata('message','<span class="message error"><strong>Error</strong>message - '.$this->lang->line('m_wrong').'  </span>');    
            redirect($this->config->item('customerdna'));
        }
           
		$data = array(
						'title'		=>	$this->lang->line('viewprospect'),
						'table'		=>	array(
                                                'value'				=>	$this->customers->getDataProspect($id),
                                                'activity'			=>	$this->customers->getLastActivity($id),
                                                'jobs'			    =>	$this->customers->getLastJob($id)
                                                
											 ),
                        'form'      =>  array('action'=>$this->config->item('cust_update')),                     
						'content'	=> 	'view',
						'menu' 		=> 	array(
												'dashboard_active'	=>	$this->config->item('empty'),
												'contact_active'	=>	$this->config->item('empty'),
                                                'contactdna_active'	=>	$this->config->item('active'),
												'activity_active'	=>	$this->config->item('empty'),
												'job_active'		=>	$this->config->item('empty'),
												'call_active'		=>	$this->config->item('empty'),
												'user_active'		=>	$this->config->item('empty'),
												'report_active'		=>	$this->config->item('empty'),
												'master_active'		=>	$this->config->item('empty'),
												'graphic_active'	=>	$this->config->item('empty'),
												'setting_active'	=>	$this->config->item('empty'),
											 ),
						'tab'		=>	array(
												'tab1'				=>	'Corporate',
												'tab1_link'			=>	$this->config->item('customerdna'),
												'tab1_active'		=>	$this->config->item('empty'),
												'tab2'				=>	'Individual',
												'tab2_link'			=>	$this->config->item('custdna_individual'),
												'tab2_active'		=>	$this->config->item('empty'),
												'tab3'				=>	$this->lang->line('viewprospect'),
                                                'tab3_link'			=>	$this->config->item('cust_viewp').$id,
												'tab3_active'		=>	$this->config->item('active'),
												'tab4'				=>	'',
												'tab5'				=>	'',
												'tab6'				=>	'',
												'tab7'				=>	$prospect,
                                                'tab7_link'			=>	$prospect_link,
												'tab7_active'		=>	$prospect_active,
												'tab8'				=>	$import,
                                                'tab8_link'			=>	$import_link,
												'tab8_active'		=>	$import_active,
											 )			
					 );
		$this->load->vars($data);
		$this->load->theme('default');
	}
    
    function uploadcsv(){
        ini_set('allow_url_fopen','On');    
        $this->load->library('csvreader');
        //$this->load->library('excel_reader'); 
        //$this->excel_reader->setOutputEncoding('CP1251'); 
        //if(file_exists('./crm-media/csv/customers.csv')):
        //    unlink('./crm-media/csv/customers.csv');
        //endif;
        $type=$this->input->post('type');
        $config['upload_path'] = './crm-media/csv/';
		$config['allowed_types'] = 'xls|csv';
		$config['max_size']	= '10000000';
		//$config['max_width']  = '1024';
		//$config['max_height']  = '768';
        
		$this->load->library('upload', $config);
		if (!$this->upload->do_upload()):
			$error = array('error' => $this->upload->display_errors());
            echo 'error';
			//$this->load->view('upload_form', $error);
		else:
			//$data = array('upload_data' => $this->upload->data());
            $data = $this->upload->data();
        endif;
        
        $value['csv'] = $this->csvreader->parse_file(site_url().'crm-media/csv/'.$data['file_name']);
        //echo site_url().'crm-media/csv/'.$data['file_name'];
        //$file=site_url().'crm-media/tes.xls';
        //$this->excel_reader->read($file);
        $this->db->orderby('id','DESC');
        $q=$this->db->get('prospects');
        $row=$q->row_array();
        if(COUNT($row)>=1):
            $id=$row['id'];
        else:
            $id=0;
        endif;
        $id=$id+1;
        //foreach($value['csv'] as $rec):
        //    echo $rec['customer_name'];
        //endforeach;
        foreach($value['csv'] as $rec):
            $data = array(
                            'id'             =>  $id,
                            'customer_name'  =>  $rec['customer_name'],
                            'type'           =>  $type,   
                            'pic'            =>  $rec['pic'],
                            'pic_pos'        =>  $rec['pic_pos'],
                            'pic2'           =>  $rec['pic2'],
                            'pic2_pos'       =>  $rec['pic2_pos'],
                            'tlp'            =>  $rec['tlp'],
                            'fax'            =>  $rec['fax'],
                            'address'        =>  $rec['address'],
                            'city'           =>  $rec['city'],
                            'zip_code'       =>  $rec['zip_code'],
                            'email'          =>  $rec['email'],
                            'desc'           =>  $rec['desc'],
                            'user_stamp'     =>  $this->session->userdata('user_id'),
                            'date_stamp'     =>  date('Y-m-d')
                         ); 
              $this->db->insert('prospects',$data);
              $id++;                        
        endforeach; 
        
        redirect($this->input->server('HTTP_REFERER'));    
		
    }
    
    function removeprospect(){
        if($this->session->userdata('user_group')!= $this->config->item('admin_dna') ):
            redirect($this->config->item('customerdna'));
        endif;
        $this->customers->getRemoveProspect();
        $this->session->set_flashdata('message','<span class="message success"><strong>Succes </strong>message - '.$this->lang->line('m_delete').'  </span>');
        redirect($this->input->server('HTTP_REFERER'));
        
    }
	
	function providecust(){
		if($this->session->userdata('user_group')!= $this->config->item('admin_dna') ):
            redirect($this->config->item('customerdna'));
        endif;
        $this->customers->getProvideProspect();
        $this->session->set_flashdata('message','<span class="message success"><strong>Succes </strong>message - '.$this->lang->line('m_delete').'  </span>');
        redirect($this->input->server('HTTP_REFERER'));
	}
	
	function removeprospectuser(){
        if($this->session->userdata('user_group')!= $this->config->item('admin_dna') ):
            redirect($this->config->item('customerdna'));
        endif;
        $this->customers->getRemoveProspectUser();
        $this->session->set_flashdata('message','<span class="message success"><strong>Succes </strong>message - '.$this->lang->line('m_delete').'  </span>');
        redirect($this->input->server('HTTP_REFERER'));   
    }
	
	function provideaddcust($id){
		$this->customers->getProvideProspectCustomer($id);
        $this->session->set_flashdata('message','<span class="message success"><strong>Succes </strong>message - '.$this->lang->line('m_delete').'  </span>');
        redirect($this->input->server('HTTP_REFERER'));
	}
    
    function report($id,$type=''){
        $file_type="xls";
        $file_name="sales_report.xls";
        header("Content-Type: application/$file_type");
        header("Content-Disposition: attachment; filename=$file_name");
        header("Pragma: no-cache");
        header("Expires: 0"); 
        set_time_limit(3360);   
		$objPHPExcel = new PHPExcel();
        $objPHPExcel->getProperties()->setTitle("title")
                    ->setDescription("description");
		$objPHPExcel->setActiveSheetIndex(0);
        
        $styleArray = array( 'borders' => array( 'allborders' => array(
                             'style' => Style_Border::BORDER_THIN )));
        $fill = array(
      			'type'       => Style_Fill::FILL_SOLID,
      			'rotation'   => 0,
      			'startcolor' => array(
      				'rgb' => 'CCCCCC'
      			),
      			'endcolor'   => array(
      				'argb' => 'CCCCCC'
      			)
      		);   
        
        $row=1;
        $col=0;
        
        $this->db->where('username',$this->input->post('username'));
        $u=$this->db->get('users');
        $u=$u->row_array();
       
       /* Produk */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'Customer Profile');
        /* Produk */
        
        $row=$row+1;
        
        /* Produk */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'ID');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getFill()->applyFromArray($fill);
        /* Produk */
        
        /* Tanggal Awal */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,'Customer Name');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+1)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->getFill()->applyFromArray($fill);
        /* Tanggal Awal */
          
        /* Tanggal Akhir */
        if($type<>'Individual'):
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,'Sector Name');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+2)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->getFill()->applyFromArray($fill);
		else:
            $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+2)->setWidth(0);
        endif;
        /* Tanggal Akhir */
        
        /* Perusahaan */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,'Group Name');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+3)->setWidth(25);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->getFill()->applyFromArray($fill);
        /* Perusahaan */
        
        /* Status */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,'Source');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+4)->setWidth(20);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->getFill()->applyFromArray($fill);
        /* Status */
        
        /* Investasi */
        if($type<>'Individual'):
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,'Status');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+5)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->getFill()->applyFromArray($fill);
        else:
            $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+5)->setWidth(0);
        endif;
        /* Investasi */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,'Pic');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+6)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,'Pic Position');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+7)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+8,$row,'Pic 2');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+8)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+9,$row,'Pic 2 Position');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+9)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+10,$row,'Telepon');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+10)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+10,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+10,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+11,$row,'Fax');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+11)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+11,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+11,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+12,$row,'Address');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+12)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+12,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+12,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+13,$row,'City');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+13)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+13,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+13,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+14,$row,'Zip Code');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+14)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+14,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+14,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+15,$row,'email');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+15)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+15,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+15,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+16,$row,'desc');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+16)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+16,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+16,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+17,$row,'PIC');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+17)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+17,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+17,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        
       
		$sql =" SELECT *,c.id ";
        $sql.=" FROM customers c ";
        $sql.=" LEFT JOIN customer_group  cg ON cg.id=c.group_id ";
        $sql.=" LEFT JOIN customer_sector cs ON cs.id=c.sector_id ";
        $sql.=" LEFT JOIN customer_source csr ON csr.id=c.source_id ";
        $sql.=" LEFT JOIN customer_status cst ON cst.id=c.status_id ";
        $sql.=" WHERE c.id=".$id;
        $q=$this->db->query($sql);
        $value=$q->row_array();
        
        $row=$row+1;
        //foreach($rows as $value):    
        /* Produk */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,$value['id']);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
        /* Produk */
        
        /* Tanggal Awal */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,$value['customer_name']);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
        /* Tanggal Awal */
          
        /* Tanggal Akhir */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,$value['sector_name']);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
		/* Tanggal Akhir */
        
        /* Perusahaan */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,$value['group_name']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
        /* Perusahaan */
        
         /* Perusahaan */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,$value['source_name']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
        /* Perusahaan */
        
        /* Status */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,$value['status_name']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
        /* Status */
        
        /* Investasi */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,$value['pic']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
        /* Investasi */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,$value['pic_pos']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
        /* Note */
        
        /* Investasi */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+8,$row,$value['pic2']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->applyFromArray($styleArray);
        /* Investasi */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+9,$row,$value['pic2_pos']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->applyFromArray($styleArray);
        /* Note */
        
        /* Investasi */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+10,$row,$value['tlp']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+10,$row)->applyFromArray($styleArray);
        /* Investasi */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+11,$row,$value['fax']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+11,$row)->applyFromArray($styleArray);
        /* Note */
        
        /* Investasi */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+12,$row,$value['address']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+12,$row)->applyFromArray($styleArray);
        /* Investasi */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+13,$row,$value['city']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+13,$row)->applyFromArray($styleArray);
        /* Note */
        
        /* Investasi */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+14,$row,$value['zip_code']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+12,$row)->applyFromArray($styleArray);
        /* Investasi */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+15,$row,$value['email']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+13,$row)->applyFromArray($styleArray);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+16,$row,$value['desc']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+13,$row)->applyFromArray($styleArray);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+17,$row,$value['rev2']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+13,$row)->applyFromArray($styleArray);
        /* Note */
        
        $row=$row+1;    
        //endforeach;
        
        // Save it as an excel 2003 file
		$objWriter = IOFactory::createWriter($objPHPExcel, "Excel5");
		$file=$file_name.'.'.$file_type;
		$path='crm-media/data/activity/week/';
        $objWriter->save($path.$file);
		redirect($path.$file,301);
    }
    
    function exportexcel(){
        $file_type="xls";
        $file_name="customer_report";
        header("Content-Type: application/$file_type");
        header("Content-Disposition: attachment; filename=$file_name");
        header("Pragma: no-cache");
        header("Expires: 0"); 
        set_time_limit(3360);   
		$objPHPExcel = new PHPExcel();
        $objPHPExcel->getProperties()->setTitle("title")
                    ->setDescription("description");
		$objPHPExcel->setActiveSheetIndex(0);
        
        $styleArray = array( 'borders' => array( 'allborders' => array(
                             'style' => Style_Border::BORDER_THIN )));
        $fill = array(
      			'type'       => Style_Fill::FILL_SOLID,
      			'rotation'   => 0,
      			'startcolor' => array(
      				'rgb' => 'CCCCCC'
      			),
      			'endcolor'   => array(
      				'argb' => 'CCCCCC'
      			)
      		);   
        
        $row=1;
        $col=0;
        
        /* Produk */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'ID');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getFill()->applyFromArray($fill);
        /* Produk */
        
        /* Tanggal Awal */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,'Customer Name');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+1)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->getFill()->applyFromArray($fill);
        /* Tanggal Awal */
          
        /* Tanggal Akhir */
        if($this->session->userdata('report_type')<>'Individual'):
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,'Sector Name');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+2)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->getFill()->applyFromArray($fill);
		 else:
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,'');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+2)->setWidth(0);
        endif;
        /* Tanggal Akhir */
        
        /* Perusahaan */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,'Group Name');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+3)->setWidth(25);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->getFill()->applyFromArray($fill);
        /* Perusahaan */
        
        /* Status */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,'Source');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+4)->setWidth(20);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->getFill()->applyFromArray($fill);
        /* Status */
        
        /* Investasi */
        if($this->session->userdata('report_type')<>'Individual'):
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,'Status');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+5)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->getFill()->applyFromArray($fill);
        else:
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,'');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+5)->setWidth(0);
        endif;
        /* Investasi */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,'Pic');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+6)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,'Pic Position');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+7)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+8,$row,'Pic 2');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+8)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+9,$row,'Pic 2 Position');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+9)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+10,$row,'Telepon');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+10)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+10,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+10,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+11,$row,'Fax');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+11)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+11,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+11,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+12,$row,'Address');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+12)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+12,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+12,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+13,$row,'City');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+13)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+13,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+13,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+14,$row,'Zip Code');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+14)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+14,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+14,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+15,$row,'email');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+15)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+15,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+15,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+16,$row,'desc');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+16)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+16,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+16,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+17,$row,'In House');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+17)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+17,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+17,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+18,$row,'DNA');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+18)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+18,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+18,$row)->getFill()->applyFromArray($fill);
        /* Note */
        
        
       
		$sql =" SELECT *,c.id ";
        $sql.=" FROM customers c ";
        $sql.=" LEFT JOIN customer_group  cg ON cg.id=c.group_id ";
        $sql.=" LEFT JOIN customer_sector cs ON cs.id=c.sector_id ";
        $sql.=" LEFT JOIN customer_source csr ON csr.id=c.source_id ";
        $sql.=" LEFT JOIN customer_status cst ON cst.id=c.status_id ";
        $sql.=" WHERE c.type='".$this->session->userdata('report_type')."'";
        $sql.=" AND c.rev2<>'' ";
        
        if($this->input->post('pic_search')<> ""):
            $sql.=" AND c.rev2='".$this->input->post('pic_search')."'";
        endif;
            
        if($this->input->post('group_search')<> ""):
            $sql.=" AND c.group_id=".$this->input->post('group_search');
        endif;
            
        if($this->input->post('sector_search')<> ""):
            $sql.=" AND c.sector_id=".$this->input->post('sector_search');
        endif;
            
        if($this->input->post('source_search')<> ""):
            $sql.=" AND c.source_id=".$this->input->post('source_search');
        endif;
            
        if($this->input->post('status_search')<>""):
            $sql.=" AND c.status_id=".$this->input->post('status_search');
        endif;
       // echo $sql;    
        $q=$this->db->query($sql);
        $rows=$q->result_array();
        
        $row=$row+1;
        foreach($rows as $value):    
        
        /* Produk */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,$value['id']);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
        /* Produk */
        
        /* Tanggal Awal */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,$value['customer_name']);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
        /* Tanggal Awal */
          
        /* Tanggal Akhir */
        if($value['type']<>'Individual'):
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,$value['sector_name']);
            $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
		else:
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,"");
        endif;
        /* Tanggal Akhir */
        
        /* Perusahaan */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,$value['group_name']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
        /* Perusahaan */
        
         /* Perusahaan */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,$value['source_name']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
        /* Perusahaan */
        
        /* Status */
        if($value['type']<>'Individual'):
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,$value['status_name']);
            $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
        else:
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,"");
        endif;
        /* Status */
        
        /* Investasi */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,$value['pic']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
        /* Investasi */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,$value['pic_pos']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
        /* Note */
        
        /* Investasi */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+8,$row,$value['pic2']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->applyFromArray($styleArray);
        /* Investasi */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+9,$row,$value['pic2_pos']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->applyFromArray($styleArray);
        /* Note */
        
        /* Investasi */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+10,$row,$value['tlp']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+10,$row)->applyFromArray($styleArray);
        /* Investasi */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+11,$row,$value['fax']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+11,$row)->applyFromArray($styleArray);
        /* Note */
        
        /* Investasi */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+12,$row,$value['address']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+12,$row)->applyFromArray($styleArray);
        /* Investasi */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+13,$row,$value['city']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+13,$row)->applyFromArray($styleArray);
        /* Note */
        
        /* Investasi */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+14,$row,$value['zip_code']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+14,$row)->applyFromArray($styleArray);
        /* Investasi */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+15,$row,$value['email']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+15,$row)->applyFromArray($styleArray);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+16,$row,$value['desc']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+16,$row)->applyFromArray($styleArray);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+17,$row,$value['rev']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+17,$row)->applyFromArray($styleArray);
        /* Note */
        
        /* Note */
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+18,$row,$value['rev2']);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+18,$row)->applyFromArray($styleArray);
        /* Note */
        
        $row=$row+1;    
        endforeach;
        
        // Save it as an excel 2003 file
		$objWriter = IOFactory::createWriter($objPHPExcel, "Excel5");
		$file=$file_name.'.'.$file_type;
		$path='crm-media/data/activity/week/';
        $objWriter->save($path.$file);
		redirect($path.$file,301);
    }
}

/* End of file dashboard.php */
/* Location: ./system/application/modules/matchbox/controllers/dashboard.php */